﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PhanQuyenTheoToChuc.aspx.cs"
    Inherits="Viewer.ToChuc.PhanQuyenTheoToChuc" %>

<%@ Register Src="~/ToChuc/UserControl/UcAddToChuc.ascx" TagName="UcAddToChuc" TagPrefix="uc" %>
<%@ Register Src="~/UserControls/UCChangeToChuc.ascx" TagName="UCChangeToChuc" TagPrefix="uc" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="../resources/css/main.css" rel="stylesheet" type="text/css" />
    <title>Untitled Page</title>
    <ext:XScript ID="XScipt1" runat="server">
    <script type="text/javascript">
        function ConfirmDeleteToChuc(id) {
            Ext.MessageBox.confirm('Thông báo', 'Bạn có chắc chắn xóa record này ko?', function doDel2(btn) {
                if (btn == 'yes') {
                    Ext.net.DirectMethods.DeleteTochuc(id);
                }
            });
        }

        var filterTree = function(el, e) {
            var tree = TreePanel,
                text = this.getRawValue();

            tree.clearFilter();

            if (Ext.isEmpty(text, false)) {
                return;
            }

            if (e.getKey() === Ext.EventObject.ESC) {
                clearFilter();
            } else {
                var re = new RegExp(".*" + text + ".*", "i");

                tree.filterBy(function(node) {
                    return re.test(node.text);
                });
            }
        };
        var clearFilter = function() {
            var field = TriggerField1,
                tree = TreePanel;

            field.setValue("");
            tree.clearFilter();
            tree.getRootNode().collapseChildNodes(true);
            tree.getRootNode().ensureVisible();
        };

        var refreshTree = function(tree, result) {
            var nodes = eval(result);
            if (nodes.length > 0) {
                tree.initChildren(nodes);
            }
            else {
                tree.getRootNode().removeChildren();
            }
        }
    </script>
    </ext:XScript>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager Locale="vi" runat="server" />
    <ext:Hidden ID="hdIdCha" runat="server">
    </ext:Hidden>
    <ext:Hidden ID="hdIdDelete" runat="server">
    </ext:Hidden>
    <ext:Hidden ID="hdNodeName" runat="server"/>
    <div>
        <ext:Viewport runat="server">
            <Items>
                <ext:BorderLayout runat="server">
                    <West>
                        <ext:TreePanel ID="TreePanel" runat="server" Width="200" Icon="ChartOrganisation" AutoScroll="true">
                            <Listeners>
                                <Click Handler="#{DirectMethods}.LoadGrid(node.id,node.text);" />
                            </Listeners>
                            <TopBar>
                                <ext:Toolbar ID="Toolbar1" runat="server">
                                    <Items>
                                        <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="Tìm kiếm:" />
                                        <ext:ToolbarSpacer />
                                        <ext:TriggerField ID="TriggerField1" runat="server" EnableKeyEvents="true">
                                            <Triggers>
                                                <ext:FieldTrigger Icon="Clear" />
                                            </Triggers>
                                            <Listeners>
                                                <KeyUp Fn="filterTree" Buffer="250" />
                                                <TriggerClick Handler="clearFilter();" />
                                            </Listeners>
                                        </ext:TriggerField>
                                    </Items>
                                </ext:Toolbar>
                            </TopBar>
                        </ext:TreePanel>
                    </West>
                    <Center>
                        <ext:Panel ID="pnl" runat="server" MonitorResize="true">
                            <Items>
                                <ext:Panel ID="Panel1" runat="server" MonitorResize="true">
                                    <Content>
                                        <table style="height: 50px;">
                                            <tr>
                                                <td>
                                                    <ext:TextField ID="txtTenToChuc" runat="server" EmptyText="Nhập tên tổ chức ">
                                                        <ToolTips>
                                                            <ext:ToolTip Html="Tên tổ chức" runat="server" />
                                                        </ToolTips>
                                                    </ext:TextField>
                                                </td>
                                                <td class="font">
                                                    <ext:ComboBox ID="cbbTochucCha" runat="server" DisplayField="TenToChucFull" ValueField="ToChucID"
                                                        EmptyText="Chọn tổ chức cha">
                                                        <ToolTips>
                                                            <ext:ToolTip ID="ToolTip1" Html="Tổ chức cha" runat="server" />
                                                        </ToolTips>
                                                        <Store>
                                                            <ext:Store ID="storeToChucCha" runat="server">
                                                                <Reader>
                                                                    <ext:JsonReader IDProperty="ToChucID">
                                                                        <Fields>
                                                                            <ext:RecordField Name="ToChucID" />
                                                                            <ext:RecordField Name="TenToChucFull" />
                                                                        </Fields>
                                                                    </ext:JsonReader>
                                                                </Reader>
                                                            </ext:Store>
                                                        </Store>
                                                        <Triggers>
                                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                                        </Triggers>
                                                        <Listeners>
                                                            <Select Handler="this.triggers[0].show();" />
                                                            <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                            <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                </td>
                                                <td>
                                                    <ext:ComboBox ID="cbbXepHang" runat="server" DisplayField="CodeValue" ValueField="CodeID"
                                                        EmptyText="Chọn xếp hạng">
                                                        <Store>
                                                            <ext:Store ID="storeXepHang" runat="server">
                                                                <Reader>
                                                                    <ext:JsonReader IDProperty="CodeID">
                                                                        <Fields>
                                                                            <ext:RecordField Name="CodeID" />
                                                                            <ext:RecordField Name="CodeValue" />
                                                                        </Fields>
                                                                    </ext:JsonReader>
                                                                </Reader>
                                                            </ext:Store>
                                                        </Store>
                                                        <ToolTips>
                                                            <ext:ToolTip ID="ToolTip2" Html="Xếp hạng" runat="server" />
                                                        </ToolTips>
                                                        <Triggers>
                                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                                        </Triggers>
                                                        <Listeners>
                                                            <Select Handler="this.triggers[0].show();" />
                                                            <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                            <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                </td>
                                                <td>
                                                    <ext:ComboBox ID="cbbKhoi" runat="server" DisplayField="CodeValue" ValueField="CodeID"
                                                        EmptyText="Chọn khối">
                                                        <Store>
                                                            <ext:Store ID="storeKhoi" runat="server">
                                                                <Reader>
                                                                    <ext:JsonReader IDProperty="CodeID">
                                                                        <Fields>
                                                                            <ext:RecordField Name="CodeID" />
                                                                            <ext:RecordField Name="CodeValue" />
                                                                        </Fields>
                                                                    </ext:JsonReader>
                                                                </Reader>
                                                            </ext:Store>
                                                        </Store>
                                                        <ToolTips>
                                                            <ext:ToolTip ID="ToolTip3" Html="Khối quản lí" runat="server" />
                                                        </ToolTips>
                                                        <Triggers>
                                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                                        </Triggers>
                                                        <Listeners>
                                                            <Select Handler="this.triggers[0].show();" />
                                                            <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                            <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                </td>
                                                <td>
                                                    <ext:Hidden ID="hdNodeId" runat="server">
                                                    </ext:Hidden>
                                                    <ext:Button ID="btnSearch" runat="server" Icon="Zoom" Text="Tìm kiếm">
                                                        <DirectEvents>
                                                            <Click OnEvent="btnSearch_Click">
                                                            </Click>
                                                        </DirectEvents>
                                                    </ext:Button>
                                                </td>
                                            </tr>
                                        </table>
                                    </Content>
                                </ext:Panel>
                                <ext:Panel ID="Panel2" runat="server" MonitorResize="true" Layout="Fit">
                                    <Content>
                                        <ext:GridPanel ID="grdToChuc" runat="server" Height="490" AutoExpandColumn="GhiChu"
                                            StripeRows="true" MonitorResize="true" AutoWidth="true">
                                            <ColumnModel ID="ColumnModel1" runat="server">
                                                <Columns>
                                                    <ext:CommandColumn Width="40" ColumnID="Command" Locked="true">
                                                        <Commands>
                                                            <ext:GridCommand>
                                                                <Menu>
                                                                    <Items>
                                                                        <ext:MenuCommand Text="Xem chi tiết" CommandName="View" Icon="LayoutHeader" />
                                                                        <ext:MenuCommand Text="Sửa " CommandName="Edit" Icon="ApplicationEdit" />
                                                                        <ext:MenuCommand Text="Xóa" CommandName="Delete" Icon="Delete" Cls="menuItemTop" />
                                                                        <ext:MenuCommand Text="Thay đổi tổ chức trực thuộc" CommandName="Change" Icon="ArrowRefresh"
                                                                            Cls="menuItemTop" />
                                                                    </Items>
                                                                </Menu>
                                                            </ext:GridCommand>
                                                        </Commands>
                                                    </ext:CommandColumn>
                                                    <ext:Column Header="Tên tổ chức" DataIndex="TenToChucFull" Resizable="true" Width="100" />
                                                    <ext:Column Header="Tổ chức trực thuộc" DataIndex="Tencha" Resizable="true" Width="150" />
                                                    <ext:Column Header="Xếp hạng đơn vị" DataIndex="XepHang" Resizable="true" Width="100" />
                                                    <ext:Column Header="Khối quản lí" DataIndex="KhoiQuanLi" Resizable="true" Width="100" />
                                                    <ext:Column Header="Đia chỉ" DataIndex="DiaChi" Resizable="true" Width="100" />
                                                    <ext:Column Header="Ghi chú" DataIndex="GhiChu" Resizable="true" />
                                                </Columns>
                                            </ColumnModel>
                                            <SelectionModel>
                                                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                                            </SelectionModel>
                                            <Listeners>
                                                <Command Handler="if(command=='Change'){#{DirectMethods}.ShowDialog('Change',record.id);} else if(command=='View'){#{DirectMethods}.ShowDialog('View',record.id);} else if(command=='Edit'){#{DirectMethods}.ShowDialog('Edit',record.id);}else if(command=='Delete'){ConfirmDeleteToChuc(record.id);}" />
                                            </Listeners>
                                            <TopBar>
                                                <ext:Toolbar ID="Toolbar" runat="server" LabelAlign="Right">
                                                    <Items>
                                                        <ext:Button ID="btnAdd" runat="server" Text="Tạo mới" IconAlign="Left" Icon="Add">
                                                            <DirectEvents>
                                                                <Click OnEvent="btnAddNew_Click">
                                                                </Click>
                                                            </DirectEvents>
                                                        </ext:Button>
                                                    </Items>
                                                </ext:Toolbar>
                                            </TopBar>
                                            <BottomBar>
                                                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageIndex="1" PageSize="20"
                                                    HideRefresh="true">
                                                </ext:PagingToolbar>
                                            </BottomBar>
                                            <Store>
                                                <ext:Store ID="storeTochuc" runat="server">
                                                    <Reader>
                                                        <ext:JsonReader IDProperty="Id">
                                                            <Fields>
                                                                <ext:RecordField Name="Id" />
                                                                <ext:RecordField Name="TenToChucFull" />
                                                                <ext:RecordField Name="Tencha" />
                                                                <ext:RecordField Name="XepHang" />
                                                                <ext:RecordField Name="KhoiQuanLi" />
                                                                <ext:RecordField Name="DiaChi" />
                                                                <ext:RecordField Name="GhiChu" />
                                                                <ext:RecordField Name="DiaChiId" />
                                                            </Fields>
                                                        </ext:JsonReader>
                                                    </Reader>
                                                </ext:Store>
                                            </Store>
                                        </ext:GridPanel>
                                    </Content>
                                </ext:Panel>
                            </Items>
                        </ext:Panel>
                    </Center>
                </ext:BorderLayout>
            </Items>
        </ext:Viewport>
        <uc:UcAddToChuc ID="UcAddToChuc" runat="server"></uc:UcAddToChuc>
        <uc:UCChangeToChuc ID="UCChangeToChuc" runat="server"></uc:UCChangeToChuc>
    </div>
    </form>
</body>
</html>
